/**
 * 
 */
package org.mspring.mlog.web.listener;

import javax.servlet.ServletContextEvent;

import org.apache.log4j.Logger;
import org.mspring.mlog.core.ServiceFactory;
import org.mspring.mlog.service.stat.TopicStatService;
import org.mspring.platform.web.WebContext;
import org.mspring.platform.web.listener.AbstractContextLoaderListener;

/**
 * @author Gao Youbo
 * @since 2013-1-8
 * @Description
 * @TODO
 */
public class StandardContextLoaderListener extends AbstractContextLoaderListener {

    private static final Logger log = Logger.getLogger(StandardContextLoaderListener.class);

    @Override
    public void afterContextInitialized(ServletContextEvent event) {
        // TODO Auto-generated method stub
        WebContext.getInstance().setServletContext(event.getServletContext());
        ServiceFactory.getJobService().loadJobServer();
        log.info("container has initialized.");
    }

    @Override
    public void beforeContextDestroyed(ServletContextEvent event) {
        // TODO Auto-generated method stub
        TopicStatService topicStatService = ServiceFactory.getBean(TopicStatService.class);
        topicStatService.views2DB();
        log.info("container has destroyed.");
    }

}
